package cn.house.houseai.mapper;

import cn.house.houseai.entify.Device;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 羡y
 * @date 2024/9/27
 * @Description
 */
@Mapper
public interface DeviceMapper {
    //查询当前用户使用的设备
    @Select("SELECT device_id,user_id,device_type, status, energy_consumption FROM devices WHERE user_id = #{userId}")
    List<Device> queryId(Integer userId);
    /**
     * 当前用户添加设备数据
     * @param device
     * @return
     */

    @Insert("INSERT INTO devices (user_id, device_type, status, energy_consumption) " +
            "VALUES (#{user_id}, #{device.device_type}, #{device.status}, #{device.energy_consumption})")
    int insertDevice(@Param("user_id") int user_id, @Param("device") Device device);

    /**
     * 用户修改设备数据
     * @param device
     * @return
     */
    int updateDevice(@Param("userId") int user_id, @Param("device") Device device);


}
